<template>
  <div
    class="wrap-item"
    :style="{
      '--scroll-width': '80px',
    }"
  >
    <div class="wrap-btn-group">
      <span class="wrap-btn wrap-go-back" @click="go">返回</span>
    </div>
    <!-- 基本信息 -->
    <div class="wrap-other-roll">
      <!-- 基础信息 -->
      <div class="card">
        <div class="title">基础信息</div>
        <el-descriptions
          class="margin-top"
          :column="3"
          direction="vertical"
          border
        >
          <el-descriptions-item>
            <template slot="label"> 服务编号 </template>
            {{ basic.serviceNo }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 服务名称 </template>
            {{ basic.serviceName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 调用时间 </template>
            {{ basic.addTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 模块名称 </template>
            {{ basic.moduleName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 模块描述 </template>
            {{ basic.moduleDesc }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 方法名 </template>
            {{ basic.method }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 接口所属类名 </template>
            {{ basic.className }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 接口地址 </template>
            {{ basic.url }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 请求方式 </template>
            {{ basic.requestWay }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <!-- 请求头 -->
      <div class="card">
        <div class="title">请求头参数</div>
        <el-table :data="tableData.head" border>
          <el-table-column
            type="index"
            width="50"
            label="序号"
            align="center"
          ></el-table-column>
          <el-table-column prop="name" label="key"></el-table-column>
          <el-table-column prop="value" label="value"></el-table-column>
        </el-table>
      </div>
      <!-- 请求参数 -->
      <div class="card">
        <div class="title">请求参数</div>
        <el-empty
          v-if="JSON.stringify(tableData.param) == '{}'"
          description="暂无数据"
        ></el-empty>
        <el-card v-else>
          <json-viewer :value="tableData.param" copyable></json-viewer>
        </el-card>
      </div>
      <!-- 响应数据 -->
      <div class="card">
        <div class="title">响应数据</div>
        <el-empty
          v-if="basic.respContent == null"
          description="暂无数据"
        ></el-empty>
        <el-card v-else>
          <json-viewer :value="basic.respContent" copyable></json-viewer>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script>
import JsonViewer from 'vue-json-viewer'
export default {
  components: { JsonViewer },
  data() {
    return {
      basic: {},
      tableData: { head: [], param: {} },
    }
  },
  created() {
    this.itemList()
  },
  methods: {
    go() {
      //返回
      this.$store.dispatch('tags/delVisitedRoute', {
        path: this.$route.path,
      })
      this.$router.push('/logCenter/port')
    },
    itemList() {
      // 获取列表
      this.$axios
        .get('/logs/api/findById?id=' + this.$route.query.id)
        .then((data) => {
          this.basic = {}
          this.tableData = { head: [], param: {} }
          if (data.code == 200) {
            this.basic = data.data
            this.tableData = data.data.body
          } else {
            this.$message.error(data.msg)
          }
        })
    },
  },
}
</script>
<style lang="scss" scoped>
.card {
  padding-bottom: 20px;
  .title {
    color: #45ab49;
    border-bottom: 1px solid #45ab49;
    padding: 10px 0;
    margin-bottom: 15px;
  }
  .handle {
    float: right;
  }
}
</style>
